package com.bosssoft.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bosssoft.entity.dto.FibUserDTO;
import com.bosssoft.entity.po.FibUserPO;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author Li kexi
 * Created on 2021/8/16.14:32
 */
public interface FibUserMapper extends BaseMapper<FibUserPO> {

    /**
     * 通过用户名获取用户
     * @param username
     * @return
     */
    @Select("SELECT * \n" +
            "FROM fib_user \n" +
            "WHERE user_username = #{username} \n" +
            "limit 1")
    FibUserPO getUserByUsername(String username);

    /**
     * 通过id禁用用户
     * @param id
     * @return
     */
    @Update("UPDATE fib_user \n" +
            "SET deleted = #{status} \n" +
            "WHERE user_id = #{id}")
    int banUserById(Long id, Integer status);

    /**
     * 通过用户名禁用用户
     * @param username
     * @return
     */
    @Update("UPDATE fib_user \n" +
            "SET deleted = #{status} \n" +
            "WHERE user_username = #{username}")
    int banUserByUsername(String username, Integer status);

    /**
     * 通过用户名获取id主键
     */
    @Select("SELECT user_id \n" +
            "FROM fib_user \n " +
            "WHERE user_username = #{username} ")
    Long getIdByUsername(String username);

    /**
     * 通过用户名删除用户
     * @param username
     * @return
     */
    @Delete("DELETE FROM fib_user \n" +
            "WHERE user_username = #{username}")
    int deleteUserByUsername(String username);

    int updateBatch(List<FibUserPO> list);

    int updateBatchSelective(List<FibUserPO> list);

    int batchInsert(@Param("list") List<FibUserPO> list);

    int insertOrUpdate(FibUserPO record);

    int insertOrUpdateSelective(FibUserPO record);

    // 以下方法仅供测试用

    @Select("SELECT * \n" +
            "FROM fib_user")
    List<FibUserPO> getAllUser();
}